package com.ruoyi.project.question.info.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.question.info.domain.QuestionInfo;
import com.ruoyi.project.question.info.service.IQuestionInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 问卷问题表Controller
 * 
 * @author Bandit
 * @date 2021-12-14
 */
@Controller
@RequestMapping("/question/info")
public class QuestionInfoController extends BaseController
{
    private String prefix = "question/info";

    @Autowired
    private IQuestionInfoService questionInfoService;

    @RequiresPermissions("question:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询问卷问题表列表
     */
    @RequiresPermissions("question:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QuestionInfo questionInfo)
    {
        startPage();
        List<QuestionInfo> list = questionInfoService.selectQuestionInfoList(questionInfo);
        return getDataTable(list);
    }

    /**
     * 导出问卷问题表列表
     */
    @RequiresPermissions("question:info:export")
    @Log(title = "问卷问题表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QuestionInfo questionInfo)
    {
        List<QuestionInfo> list = questionInfoService.selectQuestionInfoList(questionInfo);
        ExcelUtil<QuestionInfo> util = new ExcelUtil<QuestionInfo>(QuestionInfo.class);
        return util.exportExcel(list, "问卷问题表数据");
    }

    /**
     * 新增问卷问题表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存问卷问题表
     */
    @RequiresPermissions("question:info:add")
    @Log(title = "问卷问题表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QuestionInfo questionInfo)
    {
        return toAjax(questionInfoService.insertQuestionInfo(questionInfo));
    }

    /**
     * 修改问卷问题表
     */
    @RequiresPermissions("question:info:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        QuestionInfo questionInfo = questionInfoService.selectQuestionInfoById(id);
        mmap.put("questionInfo", questionInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存问卷问题表
     */
    @RequiresPermissions("question:info:edit")
    @Log(title = "问卷问题表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QuestionInfo questionInfo)
    {
        return toAjax(questionInfoService.updateQuestionInfo(questionInfo));
    }

    /**
     * 删除问卷问题表
     */
    @RequiresPermissions("question:info:remove")
    @Log(title = "问卷问题表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(questionInfoService.deleteQuestionInfoByIds(ids));
    }
}
